package com.fr.data;

import com.fr.base.Parameter;
import com.fr.general.data.TableDataException;
import com.fr.stable.StringUtils;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 全国商品销售额分析
 *
 * @author liumingchun  14:28 2019-01-03
 */
public class AllCountrySalesReport extends AbstractTableData {
    // 字段名枚举
    enum FIELD_NAME {
        DATE, WEEK_DAY, STORE_SIZE,
        STORE_SIZE_ALL, SALES_AMOUNT, CUSTOMER_AMOUNT, COPIES,
        STORE_SIZE_ALL_LAST_WEEK, SALES_AMOUNT_LAST_WEEK, CUSTOMER_AMOUNT_LAST_WEEK, COPIES_LAST_WEEK,
        STORE_SIZE_ALL_LAST_YEAR, SALES_AMOUNT_LAST_YEAR, CUSTOMER_AMOUNT_LAST_YEAR, COPIES_LAST_YEAR
    }

    // 列名数组，保存程序数据集所有列名
    private String[] columNames;
    // 保存查询得到列值
    private LinkedHashSet<LinkedHashMap<String, Object>> rowData;

    // 构造函数，定义表结构，该表有10个数据列，列名为column#0，column#1，。。。。。。column#9
    public AllCountrySalesReport() {
        // 定义tableName参数
//        setDefaultParameters(new Parameter[]{new Parameter("tableName")});
        // 定义程序数据集列名
        this.parameters = new Parameter[]{new Parameter("bgnDate"), new Parameter("endDate"), new Parameter("productId"),
                new Parameter("cityId"), new Parameter("partyId")};
        // 填充字段名
        columNames = new String[FIELD_NAME.values().length];
        int i = 0;
        for (FIELD_NAME fieldName : FIELD_NAME.values()) {
            columNames[i] = fieldName.toString();
            i++;
        }
    }

    @Override
    public int getColumnCount() throws TableDataException {
        return columNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) throws TableDataException {
        return columNames[columnIndex];
    }

    @Override
    public int getRowCount() throws TableDataException {
        queryData();
        return rowData.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        queryData();
        int tempRowIndex = 0;
        for (LinkedHashMap<String, Object> row : rowData) {
            if (tempRowIndex == rowIndex) {
                return row.get(columNames[columnIndex]);
            }
            tempRowIndex += 1;
        }
        return null;
    }

    /**
     *  获取数据库连接 driverName和 url 可以换成您需要的
     * @return
     */
    public static Connection getConnection() {

        String driverName = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@10.10.201.97:1521:crmngpsd";
        String username = "zyngprd";
        String password = "zyngprd";
        Connection con = null;
        try {
            Class.forName(driverName);
            con = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return con;
    }

    // 准备数据
    public void queryData() {
        // 确保只被执行一次
        if (rowData != null) {
            return;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

//        // 保存得到的数据库表名
        String bgnDate = parameters[0].getValue().toString();
        String endDate = parameters[1].getValue().toString();
        String productId = parameters[2].getValue().toString();
        String cityId = parameters[3].getValue().toString();
        String partyId = parameters[4].getValue().toString();
//        String bgnDate = "Fri Oct 12 00:00:00 CST 2018";
//        String endDate = "Thu Oct 18 00:00:00 CST 2018";
//        String productId = "";
//        String cityId = "";
//        String partyId = "55000001','55000002','55000003";
        System.out.println("bgnDate:" + bgnDate + "endDate:" + endDate + "productId:" + productId + "cityId:" + cityId + "partyId:" + partyId);
//        String productId = "";
//        String cityId = "";
//        String partyId = "";
//        开始时间
        Date bgnDateTime = new Date(bgnDate);
//        结束时间
        Date endDateTime = new Date(endDate);
        Calendar beginCa = Calendar.getInstance();
        beginCa.setTime(bgnDateTime);
        String beginCaTime = dateFormat.format(beginCa.getTime());
        Calendar endCa = Calendar.getInstance();
        endCa.setTime(endDateTime);
        String endCaTime = dateFormat.format(endCa.getTime());
        int compareTime = endCa.get(Calendar.DAY_OF_YEAR) - beginCa.get(Calendar.DAY_OF_YEAR);

        //获得上期时间
        beginCa.add(Calendar.DATE, -1);
        String lastWeekEndDate = dateFormat.format(beginCa.getTime());
        beginCa.add(Calendar.DATE, -compareTime);
        String lastWeekBeginDate = dateFormat.format(beginCa.getTime());
        //获得上年时间
        beginCa.setTime(bgnDateTime);
        beginCa.add(Calendar.YEAR, -1);
        String lastYearBeginDate = dateFormat.format(beginCa.getTime());
        endCa.add(Calendar.YEAR, -1);
        String lastYearEndDate = dateFormat.format(endCa.getTime());

        StringBuffer conditionSql = new StringBuffer();

        if (StringUtils.isNotBlank(productId)) {
            conditionSql.append(" and v.PRODUCT_ID in('" + productId + "')");
        }
        if (StringUtils.isNotBlank(cityId)) {
            conditionSql.append(" and v.dim_id in('" + cityId + "')");
        }
//        if (StringUtils.isNotBlank(partyId)) {
//            conditionSql.append(" and v.party_id in('" + partyId + "')");
//        }

        // 构造SQL语句,并打印出来

        // 保存得到的结果集
        rowData = new LinkedHashSet<LinkedHashMap<String, Object>>();
        // 下面开始建立数据库连接，按照刚才的SQL语句进行查询
        Connection conn = getConnection();
        try {
            Statement stmt = conn.createStatement();
            //查询经销商Id
            List partyList = new ArrayList();
            if (StringUtils.isNotBlank(partyId)) {
                String[] split = partyId.replaceAll("'", "").split(",");
                LinkedHashMap<String, Object> partyMap;
                for (int i = 0; i < split.length; i++) {
                    partyMap = new LinkedHashMap<String, Object>();
                    partyMap.put("partyId", split[i]);
                    partyList.add(partyMap);
                }
            } else {
                String partyIdSql = "SELECT s.party_id FROM zdev_store_info s  GROUP BY s.party_id ORDER BY  s.party_id";
                ResultSet partyIdReportRs = stmt.executeQuery(partyIdSql.toString());
                LinkedHashMap<String, Object> partyMap;
                while (partyIdReportRs.next()) {
                    partyMap = new LinkedHashMap<String, Object>();
                    partyMap.put("partyId", partyIdReportRs.getString(1));
                    partyList.add(partyMap);
                }
                partyIdReportRs.close();
            }
            List storeSizeAllListEveryDay = new ArrayList();
            BigDecimal storeSizeAllLastWeek = new BigDecimal(0);
            BigDecimal storeSizeAllLastYear = new BigDecimal(0);
            BigDecimal storeSizeAll = new BigDecimal(0);
            for (int i = 0; i < partyList.size(); i++) {
                LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) partyList.get(i);
                String partyIdForQuery = String.valueOf(map.get("partyId"));
                //判断表是否存在
                String tableExist = "select count(1) from user_tables where table_name = 'ZDEV_SALES_DTL" + partyIdForQuery + "_V2'";
                ResultSet tableExistResultSet = stmt.executeQuery(tableExist);
                String tableExistFlag = "";
                while (tableExistResultSet.next()) {
                    tableExistFlag = tableExistResultSet.getString(1);
                }
                if ("1".equals(tableExistFlag)) {
                    //查询时间区间每天门店数 本期 每天
                    StringBuffer queryStoreSizeEveryDay = new StringBuffer();
                    queryStoreSizeEveryDay.append(" SELECT T .EXTEND2, COUNT (T .store_id) STORE_SIZE FROM ( ");
                    queryStoreSizeEveryDay.append("  SELECT distinct  s.store_id ,v.EXTEND2");
                    queryStoreSizeEveryDay.append("  FROM ZDEV_SALES_DTL" + partyIdForQuery + "_V2 V ");
                    queryStoreSizeEveryDay.append("  INNER JOIN zdev_store_info s on v.EXTEND2 = s.EXTEND1 AND s.STORE_ID = v.STORE_ID ");
                    queryStoreSizeEveryDay.append("  WHERE  V.DIM_TYPE = '01' AND s.store_status_id = 'OPEN' ");
                    queryStoreSizeEveryDay.append("  AND  v.EXTEND2 >= '" + beginCaTime + "' and  v.EXTEND2 <= '" + endCaTime + "' ");
                    queryStoreSizeEveryDay.append(conditionSql);
                    queryStoreSizeEveryDay.append(" ) T GROUP BY t.EXTEND2");
                    ResultSet storeSizeEveryDay = stmt.executeQuery(queryStoreSizeEveryDay.toString());
                    while (storeSizeEveryDay.next()) {
                        LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>();
                        String date = String.valueOf(storeSizeEveryDay.getString("EXTEND2"));
                        BigDecimal storeSize = storeSizeEveryDay.getBigDecimal("STORE_SIZE");
                        if (storeSizeAllListEveryDay.size() < 1) {
                            info.put("DATE", date);
                            info.put("STORE_SIZE", storeSize);
                            storeSizeAllListEveryDay.add(info);
                        } else {
                            //如果有日期、品牌相同的，合并
                            boolean flag = true;
                            for (int j = 0; j < storeSizeAllListEveryDay.size(); j++) {
                                LinkedHashMap<String, Object> reportMap = (LinkedHashMap<String, Object>) storeSizeAllListEveryDay.get(j);
                                if (date.equals(reportMap.get("DATE"))) {
                                    flag = false;
                                    reportMap.put("STORE_SIZE", storeSize.add((BigDecimal) reportMap.get("STORE_SIZE")));
                                    break;
                                }
                            }
                            //年月小时均不同，添加进集合中成为新的元素
                            if (flag) {
                                info.put("DATE", date);
                                info.put("STORE_SIZE", storeSize);
                                storeSizeAllListEveryDay.add(info);
                            }
                        }
                    }
                    storeSizeEveryDay.close();

                    //查询时间区间门店总数 本期
                    StringBuffer queryStoreSizeAll = new StringBuffer();
                    queryStoreSizeAll.append(" SELECT   COUNT (T .store_id) STORE_SIZE FROM ( ");
                    queryStoreSizeAll.append("  SELECT distinct  s.store_id ");
                    queryStoreSizeAll.append("  FROM ZDEV_SALES_DTL" + partyIdForQuery + "_V2 V ");
                    queryStoreSizeAll.append("  INNER JOIN zdev_store_info s on v.EXTEND2 = s.EXTEND1 AND s.STORE_ID = v.STORE_ID ");
                    queryStoreSizeAll.append("  WHERE  V.DIM_TYPE = '01' AND s.store_status_id = 'OPEN' ");
                    queryStoreSizeAll.append("  AND  v.EXTEND2 >= '" + beginCaTime + "' and  v.EXTEND2 <= '" + endCaTime + "' ");
                    queryStoreSizeAll.append(conditionSql);
                    queryStoreSizeAll.append(" ) T ");
                    ResultSet storeSizeResultSetThisWeek = stmt.executeQuery(queryStoreSizeAll.toString());
                    while (storeSizeResultSetThisWeek.next()) {
                        BigDecimal storeSize = storeSizeResultSetThisWeek.getBigDecimal("STORE_SIZE");
                        storeSizeAll = storeSizeAll.add(storeSize);
                    }
                    storeSizeResultSetThisWeek.close();

                    //查询时间区间门店总数 上期
                    StringBuffer queryStoreSizeAllLastWeek = new StringBuffer();
                    queryStoreSizeAllLastWeek.append(" SELECT   COUNT (T .store_id) STORE_SIZE FROM ( ");
                    queryStoreSizeAllLastWeek.append("  SELECT distinct  s.store_id ");
                    queryStoreSizeAllLastWeek.append("  FROM ZDEV_SALES_DTL" + partyIdForQuery + "_V2 V ");
                    queryStoreSizeAllLastWeek.append("  INNER JOIN zdev_store_info s on v.EXTEND2 = s.EXTEND1 AND s.STORE_ID = v.STORE_ID ");
                    queryStoreSizeAllLastWeek.append("  WHERE  V.DIM_TYPE = '01' AND s.store_status_id = 'OPEN' ");
                    queryStoreSizeAllLastWeek.append("  AND  v.EXTEND2 >= '" + lastWeekBeginDate + "' and  v.EXTEND2 <= '" + lastWeekEndDate + "' ");
                    queryStoreSizeAllLastWeek.append(conditionSql);
                    queryStoreSizeAllLastWeek.append(" ) T  ");
                    ResultSet storeSizeResultSetLastWeek = stmt.executeQuery(queryStoreSizeAllLastWeek.toString());
                    while (storeSizeResultSetLastWeek.next()) {
                        BigDecimal storeSize = storeSizeResultSetLastWeek.getBigDecimal("STORE_SIZE");
                        storeSizeAllLastWeek = storeSizeAllLastWeek.add(storeSize);

                    }
                    storeSizeResultSetLastWeek.close();

                    //查询时间区间门店总数 上年
                    StringBuffer queryStoreSizeAllLastYear = new StringBuffer();
                    queryStoreSizeAllLastYear.append(" SELECT   COUNT (T .store_id) STORE_SIZE FROM ( ");
                    queryStoreSizeAllLastYear.append("  SELECT distinct  s.store_id ");
                    queryStoreSizeAllLastYear.append("  FROM ZDEV_SALES_DTL" + partyIdForQuery + "_V2 V ");
                    queryStoreSizeAllLastYear.append("  INNER JOIN zdev_store_info s on v.EXTEND2 = s.EXTEND1 AND s.STORE_ID = v.STORE_ID ");
                    queryStoreSizeAllLastYear.append("  LEFT JOIN zdev_param_content z ON z.fx_code = s.brand_code AND z.fl_code = '1003'");
                    queryStoreSizeAllLastYear.append("  WHERE  V.DIM_TYPE = '01' AND s.store_status_id = 'OPEN' ");
                    queryStoreSizeAllLastYear.append("  AND  v.EXTEND2 >= '" + lastYearBeginDate + "' and  v.EXTEND2 <= '" + lastYearEndDate + "' ");
                    queryStoreSizeAllLastYear.append(conditionSql);
                    queryStoreSizeAllLastYear.append(" ) T  ");
                    ResultSet storeSizeResultSetLastYear = stmt.executeQuery(queryStoreSizeAllLastYear.toString());
                    while (storeSizeResultSetLastYear.next()) {
                        BigDecimal storeSize = storeSizeResultSetLastYear.getBigDecimal("STORE_SIZE");
                        storeSizeAllLastYear = storeSizeAllLastYear.add(storeSize);
                    }
                    storeSizeResultSetLastYear.close();
                }
            }
            //==========================================今年本周数据
            List yearWeekDataList = new ArrayList();
            //查询今年本周本城市数据
            StringBuffer querySqlThisWeek = new StringBuffer();
            querySqlThisWeek.append("SELECT DISTINCT  TEMP1.CUSTOMER_AMOUNT,TEMP1.copies,TEMP1.EXTEND1 ,TEMP1.SALES_AMOUNT,");
            querySqlThisWeek.append(" CASE  to_char(to_date(temp1.extend1,'YYYYMMDD') -1,'d')  WHEN '1' then '星期一' WHEN '2' THEN '星期二' WHEN '3' THEN '星期三' WHEN '4' THEN '星期四' WHEN '5' THEN '星期五' WHEN '6' THEN '星期六' WHEN '7' THEN '星期日' END week_day ");
            querySqlThisWeek.append("  FROM ( SELECT v.extend1,sum(v.SALES_AMOUNT) SALES_AMOUNT,sum(QUANTITY1) customer_amount,sum(v.QUANTITY2) copies  ");
            querySqlThisWeek.append("   FROM   ZDEV_SALES_H_V2 V  WHERE v.DIM_TYPE = '01' ");
            querySqlThisWeek.append("  AND  v.extend1 >= '" + beginCaTime + "' and  v.extend1 <= '" + endCaTime + "' ");
            querySqlThisWeek.append(conditionSql);
            if (StringUtils.isNotBlank(partyId)) {
                querySqlThisWeek.append(" and v.party_id in('" + partyId + "')");
            }
            querySqlThisWeek.append("  GROUP BY v.extend1  ");
            querySqlThisWeek.append(" ) TEMP1 ORDER BY TEMP1.EXTEND1");
            ResultSet resultSetThisWeek = stmt.executeQuery(querySqlThisWeek.toString());
            //今年本周
            LinkedHashMap<String, Object> thisYearWeekMap;
            while (resultSetThisWeek.next()) {
                thisYearWeekMap = new LinkedHashMap();
                thisYearWeekMap.put(FIELD_NAME.DATE.toString(), resultSetThisWeek.getString("EXTEND1"));
                thisYearWeekMap.put(FIELD_NAME.WEEK_DAY.toString(), resultSetThisWeek.getString("WEEK_DAY"));
                thisYearWeekMap.put(FIELD_NAME.SALES_AMOUNT.toString(), resultSetThisWeek.getBigDecimal("SALES_AMOUNT"));
                thisYearWeekMap.put(FIELD_NAME.CUSTOMER_AMOUNT.toString(), resultSetThisWeek.getBigDecimal("CUSTOMER_AMOUNT"));
                thisYearWeekMap.put(FIELD_NAME.COPIES.toString(), resultSetThisWeek.getBigDecimal("COPIES"));
                yearWeekDataList.add(thisYearWeekMap);
            }
            resultSetThisWeek.close();

            // ==========================================今年上周数据

            //查询上周数据
            StringBuffer yearLastWeekData = new StringBuffer();
            yearLastWeekData.append("SELECT DISTINCT  TEMP1.CUSTOMER_AMOUNT,TEMP1.copies,TEMP1.EXTEND1 ,TEMP1.SALES_AMOUNT, ");
            yearLastWeekData.append(" CASE  to_char(to_date(temp1.extend1,'YYYYMMDD') -1,'d')  WHEN '1' then '星期一' WHEN '2' THEN '星期二' WHEN '3' THEN '星期三' WHEN '4' THEN '星期四' WHEN '5' THEN '星期五' WHEN '6' THEN '星期六' WHEN '7' THEN '星期日' END week_day ");
            yearLastWeekData.append("  FROM ( SELECT v.extend1,sum(v.SALES_AMOUNT) SALES_AMOUNT,sum(QUANTITY1) customer_amount,sum(v.QUANTITY2) copies  ");
            yearLastWeekData.append("   FROM   ZDEV_SALES_H_V2 V  WHERE v.DIM_TYPE = '01' ");
            yearLastWeekData.append("  AND  v.extend1 >= '" + lastWeekBeginDate + "' and  v.extend1 <= '" + lastWeekEndDate + "' ");
            yearLastWeekData.append(conditionSql);
            if (StringUtils.isNotBlank(partyId)) {
                yearLastWeekData.append(" and v.party_id in('" + partyId + "')");
            }
            yearLastWeekData.append("  GROUP BY v.extend1  ");
            yearLastWeekData.append(" ) temp1");
            ResultSet lastWeekRs = stmt.executeQuery(yearLastWeekData.toString());
            BigDecimal salesAmountLastWeek = new BigDecimal(0);
            BigDecimal customerAmountLastWeek = new BigDecimal(0);
            BigDecimal copiesLastWeek = new BigDecimal(0);
            while (lastWeekRs.next()) {
                //合计
                salesAmountLastWeek = salesAmountLastWeek.add(lastWeekRs.getBigDecimal("SALES_AMOUNT"));
                customerAmountLastWeek = customerAmountLastWeek.add(lastWeekRs.getBigDecimal("CUSTOMER_AMOUNT"));
                copiesLastWeek = copiesLastWeek.add(lastWeekRs.getBigDecimal("COPIES"));
            }
            lastWeekRs.close();

            // ==========================================去年数据
            //查询去年数据
            StringBuffer lastYearCityData = new StringBuffer();
            //去年
            lastYearCityData.append("SELECT DISTINCT  TEMP1.CUSTOMER_AMOUNT,TEMP1.copies,TEMP1.EXTEND1 ,TEMP1.SALES_AMOUNT, ");
            lastYearCityData.append(" CASE  to_char(to_date(temp1.extend1,'YYYYMMDD') -1,'d')  WHEN '1' then '星期一' WHEN '2' THEN '星期二' WHEN '3' THEN '星期三' WHEN '4' THEN '星期四' WHEN '5' THEN '星期五' WHEN '6' THEN '星期六' WHEN '7' THEN '星期日' END week_day ");
            lastYearCityData.append("  FROM ( SELECT v.extend1,sum(v.SALES_AMOUNT) SALES_AMOUNT,sum(QUANTITY1) customer_amount,sum(v.QUANTITY2) copies  ");
            lastYearCityData.append("   FROM   ZDEV_SALES_H_V2 V  WHERE v.DIM_TYPE = '01' ");
            lastYearCityData.append("  AND  v.extend1 >= '" + lastYearBeginDate + "' and  v.extend1 <= '" + lastYearEndDate + "' ");
            lastYearCityData.append(conditionSql);
            if (StringUtils.isNotBlank(partyId)) {
                lastYearCityData.append(" and v.party_id in('" + partyId + "')");
            }
            lastYearCityData.append("  GROUP BY v.extend1  ");
            lastYearCityData.append(" ) temp1");
            ResultSet lastYearRs = stmt.executeQuery(lastYearCityData.toString());
            BigDecimal salesAmountLastYear = new BigDecimal(0);
            BigDecimal customerAmountLastYear = new BigDecimal(0);
            BigDecimal copiesLastYear = new BigDecimal(0);
            while (lastYearRs.next()) {
                //合计
                salesAmountLastYear = salesAmountLastYear.add(lastYearRs.getBigDecimal("SALES_AMOUNT"));
                customerAmountLastYear = customerAmountLastYear.add(lastYearRs.getBigDecimal("CUSTOMER_AMOUNT"));
                copiesLastYear = copiesLastYear.add(lastYearRs.getBigDecimal("COPIES"));
            }
            lastYearRs.close();
            //合并 本期每天销额、店铺数
            for (int i = 0; i < yearWeekDataList.size(); i++) {
                LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) yearWeekDataList.get(i);
                //本期时间区间门店数
                for (int k = 0; k < storeSizeAllListEveryDay.size(); k++) {
                    LinkedHashMap<String, Object> map3 = (LinkedHashMap<String, Object>) storeSizeAllListEveryDay.get(k);
                    if (map.get("DATE").equals(map3.get("DATE"))) {
                        map.put(AllCountrySalesReport.FIELD_NAME.STORE_SIZE.toString(), map3.get("STORE_SIZE"));
                        break;
                    }
                }
            }
//            DATE, WEEK_DAY, STORE_SIZE, STORE_SIZE_ALL, SALES_AMOUNT, CUSTOMER_AMOUNT, COPIES,
//                    STORE_SIZE_ALL_LAST_WEEK, SALES_AMOUNT_LAST_WEEK, CUSTOMER_AMOUNT_LAST_WEEK, COPIES_LAST_WEEK,
//                    STORE_SIZE_ALL_LAST_YEAR, SALES_AMOUNT_LAST_YEAR, CUSTOMER_AMOUNT_LAST_YEAR, COPIES_LAST_YEAR
            for (int i = 0; i < yearWeekDataList.size(); i++) {
                LinkedHashMap<String, Object> linkedHashMap = (LinkedHashMap) yearWeekDataList.get(i);
                LinkedHashMap<String, Object> row = new LinkedHashMap<String, Object>();
                // 注：字段赋值的顺序，要跟枚举里的顺序一样
                row.put(FIELD_NAME.DATE.toString(), linkedHashMap.get(FIELD_NAME.DATE.toString()));
                row.put(FIELD_NAME.WEEK_DAY.toString(), linkedHashMap.get(FIELD_NAME.WEEK_DAY.toString()));
                row.put(FIELD_NAME.STORE_SIZE.toString(), linkedHashMap.get(FIELD_NAME.STORE_SIZE.toString()));
                row.put(FIELD_NAME.STORE_SIZE_ALL.toString(), storeSizeAll);
                row.put(FIELD_NAME.SALES_AMOUNT.toString(), linkedHashMap.get(FIELD_NAME.SALES_AMOUNT.toString()));
                row.put(FIELD_NAME.CUSTOMER_AMOUNT.toString(), linkedHashMap.get(FIELD_NAME.CUSTOMER_AMOUNT.toString()));
                row.put(FIELD_NAME.COPIES.toString(), linkedHashMap.get(FIELD_NAME.COPIES.toString()));
                row.put(FIELD_NAME.STORE_SIZE_ALL_LAST_WEEK.toString(), storeSizeAllLastWeek);
                row.put(FIELD_NAME.SALES_AMOUNT_LAST_WEEK.toString(), salesAmountLastWeek);
                row.put(FIELD_NAME.CUSTOMER_AMOUNT_LAST_WEEK.toString(), customerAmountLastWeek);
                row.put(FIELD_NAME.COPIES_LAST_WEEK.toString(), copiesLastWeek);
                row.put(FIELD_NAME.STORE_SIZE_ALL_LAST_YEAR.toString(), storeSizeAllLastYear);
                row.put(FIELD_NAME.SALES_AMOUNT_LAST_YEAR.toString(), salesAmountLastYear);
                row.put(FIELD_NAME.CUSTOMER_AMOUNT_LAST_YEAR.toString(), customerAmountLastYear);
                row.put(FIELD_NAME.COPIES_LAST_YEAR.toString(), copiesLastYear);
                rowData.add(row);
            }
            System.out.println(rowData.toString());
            // 释放数据库资源
            stmt.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    // 释放一些资源，因为可能会有重复调用，所以需释放valueList，将上次查询的结果释放掉
    @Override
    public void release() throws Exception {
        super.release();
        this.rowData = null;
    }
}
